package com.alog.yzd.jdbc.hm;


import java.sql.*;

public class BatchTest {

    public static void main(String[] args){
        addUser();
    }

    public static void addUser() {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try{
            String sql = "insert into user (id, name, pwd, birth) values (?, ?, ?, ?)";
            conn = JdbcUtils2.getConnction();
            ps = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
            for(int i = 100; i < 150; i++){
                ps.setInt(1,i);
                ps.setString(2,"name" + i);
                ps.setString(3,"pwd" + i);
                ps.setDate(4, new java.sql.Date(2018,11,12));
                ps.addBatch();
            }
            ps.executeBatch();
        } catch(SQLException e){
            throw new DaoException(e.getMessage(), e);
        } finally {
            JdbcUtils2.release(rs, ps, conn);
        }
    }
}
